﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace RegexTester
{
    public partial class GrepTester : Form
    {
        public GrepTester()
        {
            InitializeComponent();
        }

        private void ClearButton_Click(object sender, EventArgs e)
        {
            resultBox.Clear();
        }

        private void ExecButton_Click(object sender, EventArgs e)
        {
            Regex testRegex = new Regex(regexBox.Text);
            resultBox.AppendText("regex : " + regexBox.Text + Environment.NewLine);
            Match testMatch = testRegex.Match(inputBox.Text);
            resultBox.AppendText("input : " + inputBox.Text + Environment.NewLine);

            if (testMatch.Success)
            {
                int numMatches = 0;
                resultBox.AppendText("Successful Match!" + Environment.NewLine);
                while (testMatch.Success)
                {
                    resultBox.AppendText(testMatch.Value + Environment.NewLine);
                    testMatch = testMatch.NextMatch();
                    numMatches++;
                }
                resultBox.AppendText("Found " + numMatches + " matches.");

            }
            else
            {
                resultBox.AppendText("No Match!" + Environment.NewLine);
            }
        }


    }
}
